package cn.tedu._06interceptor.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor1 implements HandlerInterceptor {
    /**
     * 1.拦截的是请求:权限校验等
     * @param request 请求对象
     * @param response 响应对象
     * @param handler 处理器方法
     * @return true-放行 false-过滤
     * @throws Exception 异常对象
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("1.第一个拦截器的preHandle执行");
        return true;
    }

    /**
     * 2.拦截的响应
     * @param request 请求对象
     * @param response 响应对象
     * @param handler 控制器方法
     * @param modelAndView 控制器方法返回的数据
     * @throws Exception 异常对象
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("2.第一个拦截器的postHandle执行");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("3.第一个拦截器的afterCompletion执行");
    }
}
